/*
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
*/

#ifndef MEM_POOL_COMM_H
#define MEM_POOL_COMM_H

#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/semaphore.h>

enum mem_node_type {
    ARGS_MEM_NODE = 0,
    DMA_MEM_NODE = 1
};

struct mem_node {
    void* vaddr;
    uint64_t paddr;
    struct list_head list;
};

struct mem_pool_info {
    uint32_t mem_size; // 内存池总大小
    uint32_t node_size; // 单个node大小
    uint32_t mem_node_num; // 内存池节点总个数

    struct mem_node node_list; // 内存池节点链表
    void* base_vaddr; // 内存池虚拟基地址
    uint64_t base_paddr; // 内存池物理基地址
    void* base_nodes_addr; // 内存池节点基地址

    struct mutex mtx;
    struct semaphore sem;

    uint32_t is_inited;
    uint32_t pool_id; // 本内存池序号
};

typedef int32_t (*init)(struct mem_pool_info* args_pool);
typedef void (*deinit)(struct mem_pool_info* args_pool);

#endif // #ifndef MEM_POOL_COMM_H